import axios from 'axios';

const token = 'sk-q0P1xUvfhGSsNAZxPrUbMCKRZ0pMCTH66A2BV0u6LQ94HAA0';
const reqUrl = 'https://api.deepbricks.ai/v1/chat/completions';

const headers = {
  'Content-Type': 'application/json',
  Connection: 'keep-alive',
  Accept: '*/*',
  Authorization: `Bearer ${token}`,
};

const sendToAi = async (content) => {
  return new Promise((resolve, reject) => {
    axios({
      method: 'post',
      url: reqUrl,
      headers,
      data: {
        // model: 'gpt-4o-mini',
        model: 'gpt-3.5-turbo',
        messages: [
          {
            role: 'user',
            content: `'${content}' 帮我用小红书的语气改写这段话`,
          },
        ],
      },
    })
      .then(({ data }) => {
        if (data.choices && data.choices.length > 0) {
          resolve({
            data: data.choices[0].message.content,
          });
        }
      })
      .catch((err) => {
        reject({
          data: err,
          code: -1,
        });
      });
  });
};

export { sendToAi };
